import { createStore,applyMiddleware } from "redux";
import logger from 'redux-logger'
import thunk from 'redux-thunk'
import reducer from './reducer'
import {persistStore,persistReducer} from 'redux-persist'
import storage from "redux-persist/lib/storage";

//对reducer进行 持久化处理
const persistedReducer = persistReducer({key:'root',storage},reducer)

var logger2 = function({dispatch,getState}){
    return function(next){
        return function(action){
            console.log('logger2',getState());
            return next(action)//移交控制器给下一个中间件
        }
    }
}

//创建一个唯一的store
//applyMiddleware()应用中间件(插件)
let store = createStore(persistedReducer,applyMiddleware(logger2,thunk,logger))

//对唯一的store进行持久化处理
let persistor = persistStore(store)




export {
    store,
    persistor
    }